# The following code produces the plots for the relative importance of variables
#
# rel.Imp <- sienaRI(data=multiPtaData, multians4)
# plot(rel.Imp[[1]], file="relativeImportanceNegList.pdf", addPieChart= FALSE, legend = TRUE)
# plot(rel.Imp[[2]], file="relativeImportancePosList.pdf", addPieChart= FALSE, legend = TRUE)

# relativeImportanceNeg <- read.table(file = "RelativeImportanceNeglist.txt", header  = TRUE,sep = "\t", dec = ".", quote ="\"'")
# negListBalance <- relativeImportanceNeg$balance
# negListSqrtDegreeAlter <- relativeImportanceNeg$sqrt.degree.alter
# negListlnUsTrade <- relativeImportanceNeg$lnUsTrade
# negListusAlliance <- relativeImportanceNeg$usAlliance
# negListusGats <- relativeImportanceNeg$gatsCommittments
# names(negListBalance) <- relativeImportanceNeg$year
# names(negListSqrtDegreeAlter) <- relativeImportanceNeg$year
# names(negListlnUsTrade) <- relativeImportanceNeg$year
# names(negListusAlliance) <- relativeImportanceNeg$year
# names(negListusGats) <- relativeImportanceNeg$year
# 
# negListSignificantVars <- cbind(negListBalance, negListSqrtDegreeAlter, negListusAlliance, negListlnUsTrade, negListusGats)
# negListSignificantVars
# pdf("RelativeImportanceNegListByYear.pdf")
# coloursNeg <- grey.colors(5, start = 0.3, end = 0.9, gamma = 2.2, alpha = NULL)
# # par(ps = 18)
# barplot(t(negListSignificantVars),
#         beside = FALSE,
#         legend=FALSE,
#         xlab = "Year",
#         ylab = "Relative importance of variable",
#         ylim = c(0,1),
#         col = coloursNeg,
#         main = "Negative-list PTAs")
# legend.neg.txt <- c("Balance", "sqrt of Degree of Alter", "US Alliance", "US Trade", "GATS commitments")
# # legend.neg.txt <- c("GATS commitments", "US Trade", "US Alliance", "sqrt of Degree of Alter", "Balance")
# legend("topright", legend= legend.neg.txt, fill = coloursNeg, bty = "n")
# dev.off()
# 
# # Create the same graph for the positive list network
# 
# relativeImportancePos <- read.table(file = "RelativeImportancePoslist.txt", header  = TRUE,sep = "\t", dec = ".", quote ="\"'")
# posListSqrtDegreeAlter <- relativeImportancePos$sqrt.degree.alter
# posListDemocracy <- relativeImportancePos$Democracy
# posListDemocracyInteraction <- relativeImportancePos$DemocracyEgoXDemocracyAlter
# posListIncome <- relativeImportancePos$Income
# posListLnUsTrade <- relativeImportancePos$lnUsTrade
# posListServicesTrade <- relativeImportancePos$servicesTrade
# posListUsFdi <- relativeImportancePos$usFdi
# 
# 
# names(posListSqrtDegreeAlter) <- relativeImportancePos$year
# names(posListDemocracy) <- relativeImportancePos$year
# names(posListDemocracyInteraction) <- relativeImportancePos$year
# names(posListIncome) <- relativeImportancePos$year
# names(posListLnUsTrade) <- relativeImportancePos$year
# names(posListServicesTrade) <- relativeImportancePos$year
# names(posListUsFdi) <- relativeImportancePos$year
# 
# posListSignificantVars <- cbind(posListSqrtDegreeAlter, posListDemocracy, posListDemocracyInteraction, 
#                                 posListIncome, posListLnUsTrade, posListServicesTrade, posListUsFdi)
# posListSignificantVars
# pdf("RelativeImportancePosListByYear.pdf")
# coloursPos <- grey.colors(7, start = 0.1, end = 1, gamma = 2.2, alpha = NULL)
# par(xpd=TRUE)
# barplot(t(posListSignificantVars),
#         beside = FALSE,
#         legend=FALSE,
#         xlab = "Year",
#         ylab = "Relative importance of variable",
#         ylim = c(0,1),
#         col = coloursPos,
#         main = "Positive-list PTAs"
#         )
# legend.pos.txt <- c("sqrt of Degree of Alter", "Democracy", "Democracy Interaction", 
#                     "GDP", "US Trade", "Services Trade/GDP", "US FDI")
# legend("topright", legend= legend.pos.txt, fill = coloursPos, bty = "n", inset=c(0,-.05))
# dev.off()